<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../vue.js"></script>
  </head>
  <body>
    <div id="app">
      <prodect-item
        v-for="prodect in prodects"
        :key="prodect.id"
        :title="prodect.title"
        @count-change="totalCount++"
      ></prodect-item>
    </div>

    <script>
      const Feature = Vue.component("prodect-item", {
        props: ["title"],
        template:
          "<div><span>商品名称：{{title}} 商品个数{{count}}</span>" +
          "<button @click=counts>+1</button></div>",
        data() {
          return {
            count: 0,
          };
        },
        methods: {
          counts() {
            this.$emit("count-change");
            this.count++;
          },
        },
      });
      var vm = new Vue({
        el: "#app",
        data: {
          prodects: [
            {
              id: 1,
              title: "苹果一斤",
            },
            {
              id: 2,
              title: "苹果两斤",
            },
            {
              id: 3,
              title: "苹果三斤",
            },
          ],
          totalCount: 0,
        },
      });
    </script>
  </body>
</html>
